# -*- coding = utf-8 -*-
# @Author: Wchime
# @time: 2023/2/8 14:14
# @file: serializers.py

from rest_framework import serializers
from goodsManage import models


class GoodsTypeSeriallizer(serializers.ModelSerializer):
    """
    商品类型序列化
    """

    class Meta:
        model = models.GoodsType
        fields = '__all__'


class GoodsSeriallizer(serializers.ModelSerializer):
    """
    商品序列化
    """
    type_name = serializers.CharField(source='type.name', required=False)

    class Meta:
        model = models.Goods
        fields = ['id', 'name', 'sort', 'describe', 'master_id', 'price', 'shelf', 'createtime', 'updatetime', 'img',
                  'type_id', 'type_name']


class HomeGoodsSeriallizer(serializers.ModelSerializer):
    """
    商品序列化
    """
    type_name = serializers.CharField(source='type.name', required=False)

    class Meta:
        model = models.Goods
        fields = ['id', 'name', 'describe', 'price', 'img', 'type_id', 'type_name']


class HomeRushGoodsSeriallizer(serializers.ModelSerializer):
    """
    抢购商品序列化
    """
    name = serializers.CharField(source='goods.name', required=False)
    describe = serializers.CharField(source='goods.describe', required=False)
    price = serializers.CharField(source='goods.price', required=False)
    img = serializers.CharField(source='goods.img', required=False)
    type_id = serializers.CharField(source='goods.type_id', required=False)
    type_name = serializers.CharField(source='goods.type_name', required=False)


    class Meta:
        model = models.RushGoods
        fields = ['id', 'rushprice', 'number', 'total', 'type_id', 'type_name', 'describe','name', 'price', 'img', 'type_id', 'type_name']


class OrderSeriallizer(serializers.ModelSerializer):
    """
    商品序列化
    """
    goods_name = serializers.CharField(source='goods.name', required=False)
    user_name = serializers.CharField(source='user.name', required=False)

    class Meta:
        model = models.Order
        fields = ['id', 'uid', 'goods_name', 'price', 'number', 'total', 'isrush', 'user_id', 'createtime', 'user_name']

